package com.hckjsec.system.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.system.domain.SysVehicleAdministration;
import com.hckjsec.system.service.ISysVehicleAdministrationService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 车辆管理Controller
 * 
 * @author cyt
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/system/vehicle")
public class SysVehicleAdministrationController extends BaseController
{
    @Autowired
    private ISysVehicleAdministrationService sysVehicleAdministrationService;

    /**
     * 查询车辆管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysVehicleAdministration sysVehicleAdministration)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            sysVehicleAdministration.setDeptId(SecurityUtils.getDeptId());
        }
        List<SysVehicleAdministration> list = sysVehicleAdministrationService.selectSysVehicleAdministrationList(sysVehicleAdministration);
        return getDataTable(list);
    }

    /**
     * 导出车辆管理列表
     */
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysVehicleAdministration sysVehicleAdministration)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            sysVehicleAdministration.setDeptId(SecurityUtils.getDeptId());
        }
        List<SysVehicleAdministration> list = sysVehicleAdministrationService.selectSysVehicleAdministrationList(sysVehicleAdministration);
        ExcelUtil<SysVehicleAdministration> util = new ExcelUtil<SysVehicleAdministration>(SysVehicleAdministration.class);
        return util.exportExcel(list, "administration");
    }

    /**
     * 获取车辆管理详细信息
     */
    @GetMapping(value = "/{vehicleId}")
    public AjaxResult getInfo(@PathVariable("vehicleId") Long vehicleId)
    {
        return AjaxResult.success(sysVehicleAdministrationService.selectSysVehicleAdministrationById(vehicleId));
    }

    /**
     * 新增车辆管理
     */
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVehicleAdministration sysVehicleAdministration)
    {
        sysVehicleAdministration.setDeptId(SecurityUtils.getDeptId());
        sysVehicleAdministration.setOperator(SecurityUtils.getUserId());
        return toAjax(sysVehicleAdministrationService.insertSysVehicleAdministration(sysVehicleAdministration));
    }

    /**
     * 修改车辆管理
     */
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVehicleAdministration sysVehicleAdministration)
    {
        return toAjax(sysVehicleAdministrationService.updateSysVehicleAdministration(sysVehicleAdministration));
    }

    /**
     * 删除车辆管理
     */
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vehicleIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleIds)
    {
        return toAjax(sysVehicleAdministrationService.deleteSysVehicleAdministrationByIds(vehicleIds));
    }
}
